package com.zhiche.lisa.bms.controller.psup;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.psup.PsupVehicleContrast;
import com.zhiche.lisa.bms.pojo.vo.psup.PsupVehicleContrastVO;
import com.zhiche.lisa.bms.service.psup.PsupVehicleContrastService;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 人送供方车型对照表 前端控制器
 * </p>
 *
 * @author linbao
 * @since 2019-06-18
 */
@RestController
@RequestMapping("/psupVehicleContrast")
@Api(description = "人送车型对照", tags = "人送车型对照")
@Slf4j
public class PsupVehicleContrastController extends PsupSdBaseController {

    @Autowired
    private PsupVehicleContrastService psupVehicleContrastService;

    /**
     * 分页查询
     *
     * @return
     */
    @PostMapping(value = "/querySdVehicleContrastPage")
    @ApiOperation(value = "人送车队对照分页查询", notes = "人送车队对照分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PsupVehicleContrastVO.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<PsupVehicleContrastVO>> querySdVehicleContrastPage(@RequestBody Page<PsupVehicleContrast> page) {
        log.info("PsupVehicleContrastController.querySdVehicleContrastPage param: {}", page);
        RestfulResponse<Page<PsupVehicleContrastVO>> resultResponse = getSuccessResponse();
        try {
            resultResponse.setData(psupVehicleContrastService.querySdVehicleContrastPage(page));
        } catch (BaseException e) {
            log.error("PsupVehicleContrastController.querySdVehicleContrastPage error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupVehicleContrastController.querySdVehicleContrastPage error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping(value = "/getVehicleList")
    @ApiOperation(value = "人送车队对照分页查询", notes = "人送车队对照分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PsupVehicleContrast.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<PsupVehicleContrast>> getVehicleList() {
        log.info("PsupVehicleContrastController.getVehicleList");
        RestfulResponse<List<PsupVehicleContrast>> resultResponse = getSuccessResponse();
        try {
            resultResponse.setData(psupVehicleContrastService.getVehicleLit());
        } catch (BaseException e) {
            log.error("PsupVehicleContrastController.getVehicleList error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupVehicleContrastController.getVehicleList error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }
}

